BEGIN;
DROP TABLE `frontend_parthner_client`;
ALTER TABLE `frontend_item` DROP FOREIGN KEY unitName_id_refs_id_22c24b5c;
DROP TABLE `frontend_unit`;
ALTER TABLE `frontend_orderitem` DROP FOREIGN KEY order_id_refs_id_15abd92c;
DROP TABLE `frontend_order`;
ALTER TABLE `frontend_manager` DROP FOREIGN KEY postName_id_refs_id_246fa65f;
DROP TABLE `frontend_post`;
ALTER TABLE `frontend_invoiceitem` DROP FOREIGN KEY invoice_id_refs_id_7c4fc94e;
DROP TABLE `frontend_invoice`;
ALTER TABLE `frontend_item` DROP FOREIGN KEY workshop_id_refs_id_bcdf995;
ALTER TABLE `frontend_category` DROP FOREIGN KEY workshop_id_refs_id_6f63daee;
DROP TABLE `frontend_workshop`;
DROP TABLE `frontend_manager`;
ALTER TABLE `frontend_invoiceitem` DROP FOREIGN KEY item_id_refs_id_20051b77;
ALTER TABLE `frontend_orderitem` DROP FOREIGN KEY item_id_refs_id_39775d68;
DROP TABLE `frontend_item`;
DROP TABLE `frontend_client`;
DROP TABLE `frontend_invoiceitem`;
DROP TABLE `frontend_orderitem`;
DROP TABLE `frontend_category`;
DROP TABLE `frontend_parthner`;
CREATE TABLE `frontend_parthner` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `firstName` varchar(64) NOT NULL,
    `secondName` varchar(64) NOT NULL,
    `lastName` varchar(64) NOT NULL,
    `birthDate` date NOT NULL,
    `phone` varchar(128) NOT NULL,
    `mobilePhone` varchar(128) NOT NULL,
    `fax` varchar(128) NOT NULL,
    `email` varchar(75) NOT NULL,
    `www` longtext NOT NULL
)
;
CREATE TABLE `frontend_category` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `name` varchar(64) NOT NULL,
    `workshop_id` integer NOT NULL
)
;
CREATE TABLE `frontend_orderitem` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `item_id` integer NULL,
    `order_id` integer NOT NULL,
    `price` numeric(10, 3) NOT NULL,
    `quantity` integer NOT NULL,
    `width` integer NULL,
    `height` integer NULL
)
;
CREATE TABLE `frontend_invoiceitem` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `item_id` integer NULL,
    `invoice_id` integer NOT NULL,
    `price` numeric(10, 3) NOT NULL,
    `quantity` integer NOT NULL,
    `width` integer NULL,
    `height` integer NULL,
    `total` numeric(10, 3) NULL
)
;
CREATE TABLE `frontend_client` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `orgName` varchar(128) NOT NULL,
    `address1` varchar(128) NOT NULL,
    `address2` varchar(128) NULL,
    `phone1` varchar(128) NOT NULL,
    `phone2` varchar(128) NULL,
    `fax` varchar(128) NULL,
    `email` varchar(75) NULL,
    `info` longtext NULL,
    `inn` varchar(128) NULL,
    `kpp` varchar(128) NULL,
    `bik` varchar(128) NULL,
    `cor_accaunt` varchar(128) NULL,
    `ras_account` varchar(128) NULL,
    `bank` varchar(128) NULL,
    `image` varchar(100) NULL,
    `www` longtext NULL
)
;
CREATE TABLE `frontend_item` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `name` longtext NOT NULL,
    `code` longtext NOT NULL,
    `categoryName_id` integer NOT NULL,
    `workshop_id` integer NOT NULL,
    `price1` numeric(10, 3) NULL,
    `price2` numeric(10, 3) NULL,
    `price3` numeric(10, 3) NULL,
    `price4` numeric(10, 3) NULL,
    `unitName_id` integer NOT NULL,
    `image` varchar(100) NULL,
    `showimage` bool NOT NULL
)
;
ALTER TABLE `frontend_orderitem` ADD CONSTRAINT item_id_refs_id_39775d68 FOREIGN KEY (`item_id`) REFERENCES `frontend_item` (`id`);
ALTER TABLE `frontend_invoiceitem` ADD CONSTRAINT item_id_refs_id_20051b77 FOREIGN KEY (`item_id`) REFERENCES `frontend_item` (`id`);
CREATE TABLE `frontend_manager` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `firstName` varchar(64) NOT NULL,
    `secondName` varchar(64) NOT NULL,
    `lastName` varchar(64) NOT NULL,
    `login` varchar(64) NOT NULL,
    `password` varchar(64) NOT NULL,
    `postName_id` integer NOT NULL
)
;
CREATE TABLE `frontend_workshop` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `name` varchar(64) NOT NULL,
    `description` longtext NOT NULL
)
;
ALTER TABLE `frontend_category` ADD CONSTRAINT workshop_id_refs_id_6f63daee FOREIGN KEY (`workshop_id`) REFERENCES `frontend_workshop` (`id`);
ALTER TABLE `frontend_item` ADD CONSTRAINT workshop_id_refs_id_bcdf995 FOREIGN KEY (`workshop_id`) REFERENCES `frontend_workshop` (`id`);
CREATE TABLE `frontend_invoice` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `client_id` integer NOT NULL,
    `dateCreate` datetime NOT NULL,
    `dateUpdate` datetime NOT NULL,
    `status` integer NOT NULL,
    `sum` numeric(10, 3) NULL
)
;
ALTER TABLE `frontend_invoiceitem` ADD CONSTRAINT invoice_id_refs_id_7c4fc94e FOREIGN KEY (`invoice_id`) REFERENCES `frontend_invoice` (`id`);
CREATE TABLE `frontend_post` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `name` varchar(64) NOT NULL,
    `description` longtext NOT NULL
)
;
ALTER TABLE `frontend_manager` ADD CONSTRAINT postName_id_refs_id_246fa65f FOREIGN KEY (`postName_id`) REFERENCES `frontend_post` (`id`);
CREATE TABLE `frontend_order` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `invoice_id` integer NULL,
    `dateCreate` datetime NOT NULL,
    `dateUpdate` datetime NOT NULL,
    `workshop_id` integer NULL,
    `status` integer NOT NULL
)
;
ALTER TABLE `frontend_orderitem` ADD CONSTRAINT order_id_refs_id_15abd92c FOREIGN KEY (`order_id`) REFERENCES `frontend_order` (`id`);
CREATE TABLE `frontend_unit` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `name` longtext NOT NULL
)
;
ALTER TABLE `frontend_item` ADD CONSTRAINT unitName_id_refs_id_22c24b5c FOREIGN KEY (`unitName_id`) REFERENCES `frontend_unit` (`id`);
CREATE TABLE `frontend_parthner_client` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `parthner_id` integer NOT NULL,
    `client_id` integer NOT NULL,
    UNIQUE (`parthner_id`, `client_id`)
)
;
ALTER TABLE `frontend_parthner_client` ADD CONSTRAINT parthner_id_refs_id_37b1dc06 FOREIGN KEY (`parthner_id`) REFERENCES `frontend_parthner` (`id`);
ALTER TABLE `frontend_parthner_client` ADD CONSTRAINT client_id_refs_id_7900907f FOREIGN KEY (`client_id`) REFERENCES `frontend_client` (`id`);
-- The following references should be added but depend on non-existent tables:
-- ALTER TABLE `frontend_item` ADD CONSTRAINT categoryName_id_refs_id_40ccebbe FOREIGN KEY (`categoryName_id`) REFERENCES `frontend_category` (`id`);
-- ALTER TABLE `frontend_invoice` ADD CONSTRAINT client_id_refs_id_465b67cc FOREIGN KEY (`client_id`) REFERENCES `frontend_client` (`id`);
-- ALTER TABLE `frontend_order` ADD CONSTRAINT invoice_id_refs_id_2eb4ccf0 FOREIGN KEY (`invoice_id`) REFERENCES `frontend_invoice` (`id`);
-- ALTER TABLE `frontend_order` ADD CONSTRAINT workshop_id_refs_id_5509b221 FOREIGN KEY (`workshop_id`) REFERENCES `frontend_workshop` (`id`);
CREATE INDEX `frontend_category_workshop_id` ON `frontend_category` (`workshop_id`);
CREATE INDEX `frontend_orderitem_item_id` ON `frontend_orderitem` (`item_id`);
CREATE INDEX `frontend_orderitem_order_id` ON `frontend_orderitem` (`order_id`);
CREATE INDEX `frontend_invoiceitem_item_id` ON `frontend_invoiceitem` (`item_id`);
CREATE INDEX `frontend_invoiceitem_invoice_id` ON `frontend_invoiceitem` (`invoice_id`);
CREATE INDEX `frontend_item_categoryName_id` ON `frontend_item` (`categoryName_id`);
CREATE INDEX `frontend_item_workshop_id` ON `frontend_item` (`workshop_id`);
CREATE INDEX `frontend_item_unitName_id` ON `frontend_item` (`unitName_id`);
CREATE INDEX `frontend_manager_postName_id` ON `frontend_manager` (`postName_id`);
CREATE INDEX `frontend_invoice_client_id` ON `frontend_invoice` (`client_id`);
CREATE INDEX `frontend_order_invoice_id` ON `frontend_order` (`invoice_id`);
CREATE INDEX `frontend_order_workshop_id` ON `frontend_order` (`workshop_id`);
COMMIT;
